<template>
  <div class="webapp-box">
    <div class="commodity bg-color">
      <div class="commodity-item" v-for="item in commodityList" :key="item.id">
        <img class="commodity-cover" :src="item.cover" />
        <div class="commodity-content">
          <span class="commodity-title">{{ item.name }}</span>
          <div class="quick-attrs" v-if="item.quickShowAttr">
            <div class="quick-attr-item" v-for="(attr,index) in item.quickShowAttr" :key="index">
              {{ attr }}
            </div>
          </div>
          <div class="price-box">
            <span class="current-price">
              <span class="price-prefix">¥</span>
              {{ item.price.toString().split(".")[0] }}</span>
            <span class="price-suffix">.{{ item.price.toString().split(".")[1] }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import {listSkusForPreview} from "@/api/product/sku";

export default {
  name: 'mallHotProduct',
  data() {
    return {
      commodityList: []
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      listSkusForPreview().then(res => {
        if (res.success) {
          this.commodityList = res.data.records
        }
      })
    }
  }
}
</script>

<style scoped>
.webapp-box {
  width: 100%;
  max-height: 500px;
  //overflow: scroll;
  font-size: 14px;
  background-color: #F7F7F7;
}


.commodity {
  display: flex;
  width: 100%;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 0 10px;
}

.commodity-item {
  padding-bottom: 10px;
  width: 48%;
  background-color: #fff;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 15px;
}

.quick-attrs {
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.quick-attr-item {
  padding: 1px 4px;
  font-size: 8px;
  background-color: #F2F2F7;
  color: #A4A4A4;
  white-space: nowrap;
  overflow: hidden;
  max-width: 40px;
  text-align: center;
  margin: 0 2px;
  text-overflow: ellipsis;
}

.price-box {
  display: inline-block;
  margin-top: 5px;
  width: 100%;
  text-align: left;
  font-weight: 600;
  font-size: 10px;
}

.price-prefix {
  font-size: 10px;
}

.price-suffix {
  font-size: 11px;
  color: #FF4142;
}

.commodity-cover {
  width: 100%;
  height: 130px;
}

.commodity-title {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-all;
}

.commodity-content {
  padding: 8px 10px;
}

.current-price {
  font-size: 14px;
  color: #FF4142;
}

.discount {
  border-radius: 2px;
  border: 1px solid #FF3333;
  padding: 1px 5px;
  font-size: 10px;
  color: #FF3333;
  margin-left: 5px;
}
</style>
